package cn.kgc.common.validator;

import cn.kgc.common.annotation.CheckAnnotation;
import cn.kgc.dto.AddSysUserDTO;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * <p>添加描述信息</p>
 *
 * @author 石浩杰
 * @since 2022年09月26日 10:04
 */
public class CheckPassword1AndPassword2Validator implements
        ConstraintValidator<CheckAnnotation, AddSysUserDTO> {

    /**
     * 验证功能
     * @param addSysUserDTO
     * @param constraintValidatorContext
     * @return
     */
    @Override
    public boolean isValid(AddSysUserDTO addSysUserDTO, ConstraintValidatorContext constraintValidatorContext) {
        if (addSysUserDTO.getPassword1().equals(addSysUserDTO.getPassword2())){ //密码和确认密码相等
            return true;
        }
        return false;
    }

    /**
     * 参数的初始化
     * @param constraintAnnotation
     */
    @Override
    public void initialize(CheckAnnotation constraintAnnotation) {
        ConstraintValidator.super.initialize(constraintAnnotation);
    }
}
